package com.huangliusong;

import org.springframework.context.ApplicationEvent;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * Spring 应用事件引导类
 * @author huangliusong
 * @since 2018/10/1
 * {@link }
 */
public class SpringApplicationEventBootStrap {
    public static void main(String[] args){
        AnnotationConfigApplicationContext context=new AnnotationConfigApplicationContext();

        //register application listener
        context.addApplicationListener(event -> {
            System.err.println("监听到事件"+event);
        });

        //start
        context.refresh();


        //publish
        context.publishEvent("你好!");
        //publish
        context.publishEvent("2001!");

        //even
        context.publishEvent(new ApplicationEvent("er") {

        });

        //close
        context.close();
    }

}
